<template>
	<view class="padding-30">
		<view class="margin-bottom30" v-for="(item,index) in list" :key="index" @click="$tools.navigateTo('/pages/index/news-info?id='+item.id)">
			<view class="fontSize-15 color-000 text-center margin-bottom20">{{item.createtime}}</view>
			<view class="padding-30 bg-fff border-radius30 margin-bottom30">
				<view class="fontSize-15 color-000 fontWeight-bold margin-bottom20">{{item.title}}</view>
				<view class="fontSize-15 color-000">{{item.content}}</view>
			</view>
		</view>
		<u-empty v-if="list.length == 0"
		        mode="list"
		        icon="http://cdn.uviewui.com/uview/empty/list.png"
				width="150px"
				height="150px"
				text="列表为空"
				textSize="18"
		>
		</u-empty>
		<view style="padding-bottom: 100rpx;">
			<u-loadmore v-if="loading" status="loading" />
			<u-loadmore v-if="isLastPage" status="nomore" />
		</view>
	</view>
</template>

<script>
	export default {
		data(){
			return{
				page:1,
				limit:10,
				list:[],
				isLastPage: false,
				loading: false,
			}
		},
		onShow() {
			this.page = 1
			this.limit = 10
			this.list = []
			this.messageList()
		},
		// 刷新 上拉刷新
		onPullDownRefresh() {
			this.page = 1
			this.isLastPage = false
			this.list = []
			this.messageList().finally(() => {
				// 停止当前页面下拉刷新
				uni.stopPullDownRefresh();
			});
		},
		// 加载下一页 下拉加载
		onReachBottom() {
			if (this.list.length >= this.page * this.limit) {
				this.isLastPage = false;
				this.page += 1;
				this.messageList();
			} else {
				this.isLastPage = true
			}
		},
		methods: {
		   async messageList(){
			  let res = await this.$http.post(this.$api.message_list,{
					page:this.page,
					limit:this.limit
				},{token:true})
			  this.list = [...this.list, ...res.data]
		   }	
		}
	}
</script>

<style lang="scss" scoped>
	
</style>